Returns the field object for the named field.

The field name is entered as text and is not case sensitive.

When using the FieldByName function with a source or destination Dataview, then you must include .Query as shown in the example below, to obtain the name of the dataset within the Dataview.

As an example, this code creates a dataset called d that is not referenced in any Dataview. In this non-dataview context, the .Query is not required. When using the function with a script dataset (including the global datasets Data1, Data2, etc), .Query is not included.

procedure ScriptEvent(var Value:Variant);
var
d : TFloClientDataset; //i.e. a dataset that is not a dataview
f : TFloField; //a field from the dataset
begin
...
//Pulls the value of the OrderNum field from the dataset
f := d.Fields.FieldByName('OrderNum').Value;
end;

In a dataset in a Dataview context, then .Query is required after the Dataview name.

procedure ScriptEvent(var Value:Variant);
var
f : TFloField; //a field from the dataset
begin
...
//Pulls the value of the OrderNum field from the source dataview
f := Source.Query.Fields.FieldByName('OrderNum').Value;
end;

This is often written in the shorthand form as <DataviewName>['<Field1Name>'].Value, or <DataviewName>['<Field1Name>'].AsString, etc.

This coding shorthand is the most common method for accessing fields. But when using shorthand, you use square brackets rather than parentheses.

For example, DR_ACCS['ACCNO'].AsString is the shorthand form of DR_ACCS.Query.Fields.FieldsByName('ACCNO').AsString.

Declaration: function FieldByName( const FieldName : string) : TField

Remember, that <DataviewName> in these examples is a placeholder for the actual name of your source or destination Dataview as per your Map. or your source Dataview for a custom script.

procedure OnMapEvent (var Value:Variant);
var
f : TField;
begin
//Returns the field called Branch - i.e. Field Name, Type, + Value
f := <DataviewName>.Query.Fields.FieldByName('Branch');
end;

The following example however, expands upon the example above, and can be run from a custom script. In this code we are setting the values that are then in turn going to be extracted using this function.

procedure ScriptEvent (var Value:Variant);
var
f : TField;
begin
//Set the values ....
f := TField.Create;
f.FieldName := 'Branch';
f.FieldType := ftInteger;
f.Value := 10;
 
//Result for value will be the enumerated value of 3 for ftInteger
LogInfo('Field Name = '+f.FieldName+' Type = '+IntToStr(f.FieldType)+' Value = '+f.AsString);
end;

Please also refer to the TField class at Field Class (TField), and TFieldType.